package io.kiki.sba.registry.server.shared.util;

import io.kiki.sba.registry.common.model.console.PersistenceData;
import io.kiki.sba.registry.store.api.DBResponse;
import io.kiki.sba.registry.store.api.OperationStatus;
import org.apache.commons.lang.StringUtils;


public class PersistenceDataParser {

    public static boolean parse2BoolIgnoreCase(PersistenceData persistenceData, boolean defaultValue) {
        if (persistenceData == null || StringUtils.isBlank(persistenceData.getData())) {
            return defaultValue;
        }
        return Boolean.parseBoolean(persistenceData.getData());
    }

    public static boolean parse2BoolIgnoreCase(DBResponse<PersistenceData> response, boolean defaultValue) {
        if (response == null || response.getEntity() == null || response.getOperationStatus() != OperationStatus.success) {
            return defaultValue;
        }
        return parse2BoolIgnoreCase(response.getEntity(), defaultValue);
    }
}
